

#include <rtc.h>
#include <devmgr.h>
#include <kmalloc.h>
#include <debug.h>

static dword io_ports[2];
dword rtc_handle;

/**
 * Detect the Real Time Clock and adds the device
 * 
 * returns - error
 */
int detect_rtc(void)
{
	int ret = 0;
	
	// assume it exists
	
	device_t *dev = (device_t*)kmalloc(sizeof(device_t));
	legacy_locator_t *locator = (legacy_locator_t*)kmalloc(sizeof(legacy_locator_t));
	if ((dev != NULL) && (locator != NULL))
	{
		dev->type = DEV_TYPE_LEGACY;
		dev->class = DEV_CLASS_SYSPERIPHERAL;
		dev->id = "RTC";
		dev->gint = 8;
		dev->handle = rtc_handle = devmgr_create_handle();
		dev->locator = locator;
		locator->ports = io_ports;
		locator->count = 2;
		dev->init = init_rtc;
		dev->start = start_rtc;
		dev->stop = stop_rtc;
		dev->handler = rtc_isr;
		devmgr_add_device(dev);
	}
	else
	{
		debugf("[RTC] Could not allocate device structure\n");
		ret = RTC_ERR_NOALLOC;
	}
	
	return ret;
}

/**
 * Initializes the RTC
 * 
 * returns - error
 */
int start_rtc(void)
{
	int ret = 0;
	
	return ret;
}

/**
 * Stops the RTC
 * 
 * returns - error
 */
int stop_rtc(void)
{
	int ret = 0;
	return ret;
}

/**
 * Handles the RTC interrupts
 * 
 * returns - error
 */
int rtc_isr(void)
{
	int ret = 0;
	return ret;
}

/**
 * Initializes the RTC
 * 
 * returns - error
 */
int init_rtc(void)
{
	int ret = 0;
	return ret;
}
